/**
 * 
 * The MIT License
 * 
 * Copyright (c) 2008 the original author or authors.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:

 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.

 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package com.googlecode.gchartjava;

import static com.googlecode.gchartjava.Color.*;
import static org.junit.Assert.assertEquals;

import org.junit.Test;

import com.googlecode.gchartjava.AxisStyle.AlignmentEnum;

/**
 * 
 * @author Julien Chastang (julien.c.chastang at gmail dot com)
 */
public class LineChartExample {

	@Test
	public void example1() {
		//Defining Line
		Line line1 = new Line(new Data(0,45,35,75,90),new Color("CA3D05"),"myWebsite.com");
		line1.setLineStyle(new LineStyle(3,1,0));
		Line line2 = new Line(new Data(80,60,35,20,10),SKYBLUE,"myCompetition.com");
		line2.setLineStyle(new LineStyle(3,1,0));

		//Defining chart.
		LineChart chart = new LineChart(line1,line2);
		chart.setSize(600, 450);
		chart.setTitle("Web Traffic|(in billions of hits)",WHITE,14);
		
		//Defining axis info and styles
		AxisStyle axisStyle = new AxisStyle(WHITE,12,AlignmentEnum.CENTER);
		AxisInfo xAxis = new AxisInfo("Nov","Dec","Jan","Feb","Mar");
		xAxis.setAxisStyle(axisStyle);
		AxisInfo xAxis2 = new AxisInfo("2007","2007","2008","2008","2008");
		xAxis2.setAxisStyle(axisStyle);
		AxisInfo yAxis = new AxisInfo("","25","50","75","100");
		AxisInfo xAxis3 = new AxisInfo(0,100,ArraysUtil.asUnmodifiableList(50f),"Month");
		xAxis3.setAxisStyle(new AxisStyle(WHITE,14,AlignmentEnum.CENTER));
		yAxis.setAxisStyle(axisStyle);
		AxisInfo yAxis2 = new AxisInfo(0,100,ArraysUtil.asUnmodifiableList(50f),"Hits");
		yAxis2.setAxisStyle(new AxisStyle(WHITE,14,AlignmentEnum.CENTER));
		yAxis2.setAxisStyle(axisStyle);
		
		//Adding axis info to chart.
		chart.addXAxisInfo(xAxis);
		chart.addXAxisInfo(xAxis2);
		chart.addXAxisInfo(xAxis3);
		chart.addYAxisInfo(yAxis);
		chart.addYAxisInfo(yAxis2);
		chart.setGrid(new LineStyle(1,3,2), 20, 20);
		
		//Defining background and chart fills.
		chart.setBackgroundFill(new SolidFill(new Color("1F1D1D")));
		LinearGradientFill fill = new LinearGradientFill(0,new Color("363433"),1);
		fill.addColorAndOffset(new Color("2E2B2A"),0);
		chart.setAreaFill(fill);
		System.out.println(chart.createURLString());
		String expectedString = "http://chart.apis.google.com/chart?cht=lc&chs=600x450&chxs=0,FFFFFF,12,0|1,FFFFFF,12,0|2,FFFFFF,12,0|3,FFFFFF,12,0|4,FFFFFF,14,0&chts=FFFFFF,14&chls=3,1,0|3,1,0&chxp=1,50.0|4,50.0&chf=bg,s,1F1D1D|c,lg,0,363433,1.0,2E2B2A,0.0&chdl=myWebsite.com|myCompetition.com&chd=e:AAczWZv.5m,zMmZWZMzGa&chtt=Web+Traffic|(in+billions+of+hits)&chg=20,20,3,2&chxr=1,0,100|4,0,100&chxt=y,y,x,x,x&chco=CA3D05,87CEEB&chxl=0:||25|50|75|100|1:|Hits|2:|Nov|Dec|Jan|Feb|Mar|3:|2007|2007|2008|2008|2008|4:|Month";
		assertEquals("Junit error", expectedString,chart.createURLString());
	}
}
